# -*- coding: utf-8 -*-
"""
作者: 肖麒
联系方式：QQ：1505448035
时间: 2025/8/4 16:23
文件作用：获取邮件, mail 需要在 Applymail（申请邮箱）返回的响应里面取
"""

import time

import requests

class GetmailApi:
    def __init__(self):
        pass

    def get_getmail(self, account, mail, req_time='0'):
        headers = {
            "Accept": "application/json, text/javascript, */*; q=0.01",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
            "Origin": "http://rootsh.com:8003",
            "Pragma": "no-cache",
            "Referer": "http://rootsh.com:8003/",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36",
            "X-Requested-With": "XMLHttpRequest"
        }
        cookies = {
            "mail": mail,
        }
        url = "http://rootsh.com:8003/getmail"
        data = {
            "mail": account,
            "time": req_time,
            "_": str(time.time() * 1000)
        }

        response = requests.post(url, headers=headers, cookies=cookies, data=data, verify=False)

        try:
            json_data = response.json()
            return json_data
        except:
            pass


if __name__ == '__main__':
    getmail_api = GetmailApi()
    mail = "2|1:0|10:1753342797|4:mail|40:MTUwNTQ0QG14bDAwMS53aW58MTc1MzM0Mjc5Nw==|75c47a1708ab459c2efa25704db991b4d46b7c14c4f14bb7d157069c13786252"
    data = getmail_api.get_getmail(mail)
    print(data)
